<?php

namespace app\admin\model\superdata;

use think\Config;
use think\Model;


class Activitytags extends Model
{



    const TAGS_STATUS_1 = 1;
    const TAGS_STATUS_0 = 0;

    // 表名
    protected $name = 'activity_tags';
    
    // 自动写入时间戳字段
    protected $autoWriteTimestamp = false;

    // 定义时间戳字段名
    protected $createTime = false;
    protected $updateTime = false;
    protected $deleteTime = false;

    // 追加属性
    protected $append = [
        'status_text',
    ];


    public function getTagsList(){
        $list = $this->getModel()->field(['id','name'])->select();
        $list = collection($list)->toArray();
        $Arr = [];
        if($list){
            foreach($list as $k=>$v){
                $Arr[$k]['id'] = ($v['id']);
                $Arr[$k]['name'] = ($v['name']);
            }
        }
        unset($list);
        return $Arr;
    }

    //新加状态字段
    public function getStatusList()
    {
        return ['0' => __('tags_status 0'),'1' => __('tags_status 1')];
    }
    //获取状态字段
    public function getStatusTextAttr($value, $data)
    {
      //  $value = $value ? $value : $data['status'];
        $value = $value ? $value : (isset($data['status']) ? $data['status'] : '');
        $list = $this->getStatusList();
        return isset($list[$value]) ? $list[$value] : '';
    }


    //通过标签获取name
    public function getTagsNameById($channel)
    {
        $ch = explode(',',$channel);
        $str = '';
        $list = $this->getModel()->field(['id','name'])->select();
        $list = collection($list)->toArray();
        foreach($list as $k=>$v){
           // echo $v['id'];die;
            if(in_array($v['id'],$ch)){
                $str .=$v['name'].',';
            }
        }

        $str = rtrim($str,',');
        unset($tagsArr);
        return $str;
    }

    public function getTagsArrNameById($channel)
    {
        $ch = explode(',',$channel);
        $str = '';
        $list = $this->getModel()->field(['id','name'])->select();
        $list = collection($list)->toArray();
        $l = [];
        foreach($list as $k=>$v){
            // echo $v['id'];die;
            // if(in_array($v['id'],$ch)){
            //  $str .=$v['name'].',';
            $l[] = $v['name'];
            //}
        }
        $l = array_filter($l);
        return $l;
    }


    public function getAtagsList(){
        $where['status'] = self::TAGS_STATUS_1;
        $list = $this->getModel()->where($where)->select();
        $list = collection($list)->toArray();
        $Arr = [];
        if($list){
            foreach($list as $k=>$v){
                $Arr[$v['id']] = $v['name'];
            }
        }
        unset($list);
        return $Arr;
    }

}
